package com.spring.nio.core.event.listener.event.constant;

import java.util.Arrays;

/**
 * @author: YSFY
 * @date: 2021-03-24 14:31
 * @pacage_name: com.spring.nio.core.event.listener.event.constant
 * @class_name: EventSourceTypeEnum
 * @description: 事件源类型枚举(定义多种事件源类型)
 */

public enum EventSourceTypeEnum {

    EXCEPTION_EVENT_SOURCE(1, "EXCEPTION_EVENT_SOURCE", "异常事件源类型");

    private Integer code;

    private String type, desc;

    EventSourceTypeEnum(Integer code, String type, String desc) {
        this.code = code;
        this.type = type;
        this.desc = desc;
    };

    public Integer getCode() {
        return code;
    }

    public String getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    public static ExceptionEventTypeEnum getEnumByCode(Integer code) {
        return Arrays.asList(ExceptionEventTypeEnum.values()).stream().filter(exceptionEventTypeEnum -> (exceptionEventTypeEnum.getCode().intValue() == code)).findFirst().get();
    }
}
